
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>如何检测死锁？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>如何检测死锁？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">方法</div>
          <div class="card-question">在通过代码审查来预防死锁时，应重点关注哪两个方面？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">方法</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应当重点关注两个方面：1. 确保多个线程在获取多个资源时遵循一致的顺序。 2. 检查是否存在循环依赖，即一个线程等待另一个线程持有的资源，而后者又在等待前者持有的资源。</div>
          </div>
          <div class="card-source">来源: 1. 代码审查</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">工具</div>
          <div class="card-question">文档中提到了哪些可以用于检测Java应用程序死锁的工具？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">工具</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到了三种主要工具：Java VisualVM、JConsole 和 Eclipse MAT（内存分析工具）。</div>
          </div>
          <div class="card-source">来源: 3. 使用工具</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">jstack 命令在死锁分析中的作用是什么？请提供一个使用示例。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">jstack 命令用于获取Java进程的线程转储文件，以便分析线程的堆栈信息。命令示例为：jstack <pid> > thread_dump.txt。</div>
          </div>
          <div class="card-source">来源: 4. 线程转储分析</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在分析线程转储文件时，我们应该特别关注哪种线程状态来识别潜在的死锁？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在分析转储文件时，应特别关注那些处于 BLOCKED 状态的线程，并进一步分析它们正在等待的锁，以判断是否存在死锁。</div>
          </div>
          <div class="card-source">来源: 4. 线程转储分析</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">文档中介绍了哪两种与死锁相关的算法，它们各自的用途是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档介绍了两种算法：1. 银行家算法，主要用于死锁预防，确保系统不会进入不安全状态。 2. 资源分配图，用于检测死锁，通过查找图中是否存在循环依赖来判断。</div>
          </div>
          <div class="card-source">来源: 5. 死锁检测算法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">根据文档中的示例代码，死锁是如何被具体模拟出来的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">死锁是通过创建两个线程模拟的：线程1先持有资源 lock1，然后尝试获取 lock2；而线程2则先持有 lock2，再尝试获取 lock1。由于两个线程相互等待对方持有的资源，最终导致了死锁。</div>
          </div>
          <div class="card-source">来源: 代码说明</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
